Imports System
Imports System.Web

Public Class WizardStep
    Inherits Panel
    Implements IVirtualPage

    Private m_ctlNavigationOptions As New Panel
    Private m_ctlNext As New AnchorButton
    Private m_ctlSave As New AnchorButton
    Private m_ctlPrevious As New AnchorButton

    Private m_sNextStep As String = Nothing
    Private m_sPreviousStep As String = Nothing

    Private m_ctlPostMethod As New Variable
    Private m_ctlSaveMethod As New Variable
    Private m_ctlInitMethod As New Variable

    Private m_ctlSID As New Variable

    Public Overloads Property [Namespace]() As String Implements IVirtualPage.Namespace
        Get
            Return MyBase.Namespace
        End Get
        Set(ByVal value As String)
            MyBase.Namespace = value
        End Set
    End Property

    Public Property NextPage() As String Implements IVirtualPage.NextPage
        Get
            Return m_sNextStep
        End Get
        Set(ByVal value As String)
            m_sNextStep = value
        End Set
    End Property

    Public Property PreviousPage() As String Implements IVirtualPage.PreviousPage
        Get
            Return m_sPreviousStep
        End Get
        Set(ByVal value As String)
            m_sPreviousStep = value
        End Set
    End Property

    Public Property PostMethod() As String
        Get
            Return m_ctlPostMethod.Value
        End Get
        Set(ByVal value As String)
            m_ctlPostMethod.Value = value
        End Set
    End Property

    Public Property SaveMethod() As String
        Get
            Return m_ctlSaveMethod.Value
        End Get
        Set(ByVal value As String)
            m_ctlSaveMethod.Value = value
        End Set
    End Property

    Public Property InitMethod() As String
        Get
            Return m_ctlInitMethod.Value
        End Get
        Set(ByVal value As String)
            m_ctlInitMethod.Value = value
        End Set
    End Property

    Public Property SID() As String
        Get
            Return m_ctlSID.Value
        End Get
        Set(ByVal value As String)
            m_ctlSID.Value = value
        End Set
    End Property

    Public Property ButtonCssClass() As String
        Get
            Return m_ctlNext.CssClass
        End Get
        Set(ByVal value As String)
            m_ctlNext.CssClass = value
            m_ctlSave.CssClass = value
            m_ctlPrevious.CssClass = value
        End Set
    End Property

    Public Sub New()
        MyBase.New()

        With m_ctlNavigationOptions
            .ObjectName = "Options"
            .CssClass = "Options"
        End With

        With m_ctlNext
            .ObjectName = "Next"
            .Text = "Continue"
        End With

        With m_ctlSave
            .ObjectName = "Save"
            .Text = "Save"
        End With

        With m_ctlPrevious
            .ObjectName = "Previous"
            .Text = "Back"
        End With

        With m_ctlPostMethod
            .Name = "_postMethod"
        End With

        With m_ctlSaveMethod
            .Name = "_saveMethod"
        End With

        With m_ctlInitMethod
            .Name = "_initMethod"
        End With

        With m_ctlSID
            .Name = "_SID"
        End With

        Style("display") = "none"

        Constructor = "new jObjective.WizardStep($('#" & DataID & "'))"
    End Sub

    Protected Overrides Sub CreateChildControls()
        MyBase.CreateChildControls()

        With m_ctlNavigationOptions.Controls
            .Add(m_ctlPrevious)
            .Add(m_ctlSave)
            .Add(m_ctlNext)
        End With

        With Controls
            .Add(m_ctlNavigationOptions)

            .Add(m_ctlInitMethod)
            .Add(m_ctlSaveMethod)
            .Add(m_ctlPostMethod)

            .Add(m_ctlSID)
        End With

        ChildControlsCreated = True
    End Sub

    Private Sub WizardStep_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If String.IsNullOrEmpty(NextPage) Then
            m_ctlNext.Style("display") = "none"
        Else
            m_ctlNext.OnClientClick = NextPage
        End If

        With m_ctlSave
            If m_ctlSaveMethod.Value = "null" Then
                .Style("display") = "none"
            Else
                .OnClientClick = [Namespace] & ".save();"
            End If
        End With

        If String.IsNullOrEmpty(PreviousPage) Then
            m_ctlPrevious.Style("display") = "none"
        Else
            m_ctlPrevious.OnClientClick = PreviousPage
        End If
    End Sub
End Class